<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('做账汇总报表信息')" />


<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <input type="hidden" id="cjrq_start" name="cjrq_start">
                    <input type="hidden" id="cjrq_end" name="cjrq_end">
                    <input type="hidden" id="fyrq_start" name="fyrq_start">
                    <input type="hidden" id="fyrq_end" name="fyrq_end">
                    <div class="layui-inline">
                        <label class="layui-form-label">店铺号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="shopno" name="shopno" placeholder="店铺号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">物流公司</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="wlgs" name="wlgs" placeholder="物流公司"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">出库单号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="fybh" name="fybh" placeholder="出库单号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">收货人</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="lxrxm" name="lxrxm" placeholder="收货人"/>
                        </div>
                    </div>

                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-normal">重置
                        </button>
                    </div>
                    <div class="moreSearch" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">波次号</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="bcbh" name="bcbh" placeholder="波次号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">发运日期</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="fyrq" name="fyrq" placeholder="请选择时间范围" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">创建日期</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="cjrq" name="cjrq" placeholder="请选择时间范围" />
                            </div>
                        </div>
                    </div>
                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>

<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<script th:inline="javascript">
    $(function () {
        $(".moreBtn").on("click", function () {
            $(".moreSearch").toggle();
        });
    });
    var dates;
    var functions = [[${functions}]];
    var ids=[];
    layui.use(['list','layer','zzpUtils','jquery','laydate','tablebutton'],function () {

        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        var $table;

        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                /*导出*/
                exportEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if (ids.length > 0) {
                        arr = $.map(ids, function (id) {
                            return id;
                        })
                    }
                    /*
                     * 以下是将ids和对象拼接在一起
                     * */
                    var str = zzpUtils.getFormJson($("#searchForm"));
                    var object2 = Object.assign({ids: arr}, str);
                    /*将条件查询和ids传到后台*/
                    zzpUtils.outputXslx({
                        url: "/wmsshippedbills/wmsShippedBillsExport",
                        data: JSON.stringify(object2)
                    });
                }

            }
        });
        //初始化
        zzpUtils.webSocket.init();
        //创建时间转换时间戳
        laydate.render({
            elem: '#cjrq',
            type: 'date',
            range: '~',
            done: function(value, date, endDate){
                if(value!=null && value!=""){
                    var start=value.toString().substring(0,value.toString().indexOf("~"));
                    var end=value.toString().substring(value.toString().indexOf("~")+1);
                    $("#cjrq_start").val(start.trim());
                    $("#cjrq_end").val(end.trim());
                }else {
                    $("#cjrq_start").val("");
                    $("#cjrq_end").val("");
                }

                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
        });
        laydate.render({
            elem: '#fyrq',
            type: 'date',
            range: '~',
            done: function(value, date, endDate){
                if(value!=null && value!=""){
                    var start=value.toString().substring(0,value.toString().indexOf("~"));
                    var end=value.toString().substring(value.toString().indexOf("~")+1);
                    $("#fyrq_start").val(start.trim());
                    $("#fyrq_end").val(end.trim());
                }else {
                    $("#fyrq_start").val("");
                    $("#fyrq_end").val("");
                }

                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
        });
        //查询list
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            autoWidth: false,
            scrollX: true,
            url: '/wmsshippedbills/list',
            columns: [{
                field: '',
                checkbox: true,
                // 显示复选框
                formatter: function (i,row) {
                    // 每次加载 checkbox 时判断当前 row 的 id 是否已经存在全局 Set() 里
                    if ($.inArray(row.id, ids) != -1) {// 因为 判断数组里有没有这个 id
                        return {
                            checked: true               // 存在则选中
                        }
                    }

                }
            }, {
                field: 'shopno',
                title: '店铺号'
            },{
                field: 'wlgs',
                title: '物流公司'
            },{
                field: 'fybh',
                title: '出库单号'
            },{
                field: 'lxrxm',
                title: '收货人'
            },{
                field: 'lxrdh',
                title: '联系电话'
            },{
                field: 'zjs',
                title: '总件数'
            },{
                field: 'zzl',
                title: '总重量'
            },{
                field: 'cjrq',
                title: '创建日期',
                sortable: true,
                //——修改——获取日期列的值进行转换
                formatter: function (value, row, index) {
                    return changeDateFormat(value)
                }
            },{
                field: 'fyrq',
                title: '发运日期',
                sortable: true,
                //——修改——获取日期列的值进行转换
                formatter: function (value, row, index) {
                    return changeDateFormat(value)
                }
            },{
                field: 'bcbh',
                title: '波次编号'
            },{
                field: 'lxrdz',
                title: '联系人地址'
            },{
                field: 'je',
                title: '单据金额'
            }
            ],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },onCheck: function (row) {
                btn_cha(row.id,1);
            },
            onUncheck: function (row) {
                btn_cha(row.id,1);
            },
            onCheckAll: function (rows) {
                $.each(rows, function (i, item) {
                    btn_cha(item.id,2);
                });

            },
            onUncheckAll: function (rows) {
                $.each(rows, function (i, item) {
                    btn_cha(item.id,3);
                });
            }
        });
        $(".inline-reset-btn").on('click',function () {
            $('#cjrq_start').val("");
            $('#cjrq_end').val("");
            $('#fyrq_start').val("");
            $('#fyrq_end').val("");
            $('#shopno').val("");
            $('#wlgs').val("");
            $('#fybh').val("");
            $('#lxrxm').val("");
            $('#bcbh').val("");
        })
    });
    //修改——转换日期格式(时间戳转换为datetime格式)
    function changeDateFormat(cellval) {
        if (cellval != null) {
            return cellval.substr(0,19);
        }
    }
    //it 1 反选/勾选 ；2 全选；3全反选
    function btn_cha(id,it) {
        if (it == 1) {

            if (ids.indexOf(id) > -1) {
                var index = ids.indexOf(id);
                if (index > -1) {
                    ids.splice(index, 1);
                }
            } else {
                ids.push(id);
            }
        } else if (it == 3) {
            if (ids.indexOf(id) > -1) {
                var index = ids.indexOf(id);
                if (index > -1) {
                    ids.splice(index, 1);
                }
            }
            /* else {
                ids.push(id);
            }*/

        } else{
            if (ids.indexOf(id) > -1) {
                var index = ids.indexOf(id);
                if (index > -1) {
                    /*ids.splice(index, 1);*/
                }
            }else {
                ids.push(id);
            }
        }
    }

</script>
</html>